#coding=utf8
import json
import os
import random

# 加载配置数据
with open("config/config.json", "rb") as _f:
    config_data = json.loads(_f.read())

# 返回模板
def out_temp_data():
    #随机回复
    return config_data["config"]["out_temp_data"][random.randint(0, len(config_data["config"]["out_temp_data"]) - 1)]

#接口路径
web_path = config_data["web"]["path"]

#返回标头
msg_head = config_data["config"]["msg_head"]

def out_communication(data:dict, username):
    # 获取当前脚本所在目录
    current_dir = os.path.dirname(os.path.abspath(__file__))
    lib_dir = os.path.join(current_dir, config_data["path"]["communication_out"] % username)
    if not os.path.exists(lib_dir):
        os.makedirs(lib_dir)
    try:
        with open(lib_dir + "communication.json", 'r') as f:
            data.update(json.loads(f.read()))
    except:
        pass
    with open(lib_dir + "communication.json", "w+") as f:
        f.write(json.dumps(data))